﻿using MediatR;
using Microsoft.AspNetCore.Mvc;
using RedDragon.Common.Dtos;
using RedDragon.ERP.API.Application.Commands.BoM;
using T.Common.Domain.Common;

namespace RedDragon.ERP.API.Controllers
{
    /// <summary>
    /// 物料清单控制器
    /// </summary>
    [Route("api/[controller]/[action]")]
    [ApiController]
    public class BoMsController : ControllerBase
    {
        private readonly IMediator mediator;
        /// <summary>
        /// 构造函数
        /// </summary>
        /// <param name="mediator"></param>
        public BoMsController(IMediator mediator)
        {
            this.mediator = mediator;
        }

        /// <summary>
        /// 物料清单添加
        /// </summary>
        /// <param name="cmd"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<Result> AddBoM(CreateBoMCommand cmd)
        {
            return await mediator.Send(cmd);
        }
        /// <summary>
        /// 物料清单显示查询列表
        /// </summary>
        /// <param name="cmd"></param>
        /// <returns></returns>
        [HttpGet]
        public async Task<Result<List<BOMDto>>> SearchBoM([FromQuery] SearchBoMCommand cmd)
        {
            return await mediator.Send(cmd);
        }
        /// <summary>
        /// 根据物料ID获取物料信息查询列表
        /// </summary>
        /// <param name="cmd"></param>
        /// <returns></returns>
        [HttpGet]
        public async Task<Result<MaterialDto>> SearchMaterialInfor([FromQuery] SearchMaterialInforCommand cmd)
        {
            return await mediator.Send(cmd);
        }
        /// <summary>
        /// 根据物料ID获取物料清单和工艺路线信息查询列表
        /// </summary>
        /// <param name="cmd"></param>
        /// <returns></returns>
        [HttpGet]
        public async Task<Result<List<MaterialIdDto>>> SearchBOMInforID([FromQuery] SearchBOMInforIDCommand cmd)
        {
            return await mediator.Send(cmd);
        }
        /// <summary>
        /// 根据工艺路线ID获取工艺路线信息查询列表
        /// </summary>
        /// <param name="cmd"></param>
        /// <returns></returns>
        [HttpGet]
        public async Task<Result> SearchProcessRoutesID([FromQuery] SearchProcessRoutesIDCommand cmd)
        {
            return await mediator.Send(cmd);
        }
        /// <summary>
        /// 根据物料清单ID获取物料清单
        /// </summary>
        /// <param name="cmd"></param>
        /// <returns></returns>
        [HttpGet]
        public async Task<Result> SearchBOMID([FromQuery] SearchBOMIDCommand cmd)
        {
            return await mediator.Send(cmd);
        }
    }
}
